import TTSDK from "./TTSDK";
import WXSDK from "./WXSDK";

export default class SDKHelper {
    private static _instance: SDKHelper = null;
    public static get Instance(): SDKHelper {
        this._instance = this._instance || new SDKHelper();
        return this._instance;
    }

    private sdk_platform: number

    public initSdk() {
        this.sdk_platform = cc.sys.platform;
        TTSDK.Instance.init();
        WXSDK.Instance.init();
    }

    public showBanner() {
        switch (this.sdk_platform) {
            case cc.sys.BYTEDANCE_GAME:
                TTSDK.Instance.showBanner();
                break;
            case cc.sys.WECHAT_GAME:
                WXSDK.Instance.showBanner();
                break;
            default:
                console.log("不处于微信和抖音平台，不展示banner广告");
                break;
        }
    }

    public showRewardVideo(options: { success: Function, fail: Function }) {
        switch (this.sdk_platform) {
            case cc.sys.BYTEDANCE_GAME:
                TTSDK.Instance.showRewardVideo(options);
                break;
            case cc.sys.WECHAT_GAME:
                WXSDK.Instance.showRewardVideo(options);
                break;
            default:
                console.log("不处于微信和抖音平台，直接成功");
                options.success && options.success();
                break;
        }
    }

    public showInterstitial() {
        switch (this.sdk_platform) {
            case cc.sys.BYTEDANCE_GAME:
                TTSDK.Instance.playScreen();
                break;
            case cc.sys.WECHAT_GAME:
                WXSDK.Instance.playScreen();
                break;
            default:
                console.log("不处于微信和抖音平台，不展示插屏广告");
                break;
        }
    }

    public subpackage(name: string, callback?: Function) {
        switch (this.sdk_platform) {
            case cc.sys.BYTEDANCE_GAME:
                TTSDK.Instance.ttSubpackage(name, callback);
                break;
            case cc.sys.WECHAT_GAME:
                WXSDK.Instance.wxSubpackage(name, callback);
                break;
            default:
                break;
        }
    }

    public ttCheckSidebar(callback?: Function) {
        if (this.sdk_platform !== cc.sys.BYTEDANCE_GAME) {
            callback && callback(false);
        } else {
            TTSDK.Instance.checkSidebar(callback);
        }
    }

    public ttShowSidebar(options: { success?: Function, fail?: Function }) {
        if (this.sdk_platform !== cc.sys.BYTEDANCE_GAME) {
            options.fail && options.fail();
        } else {
            TTSDK.Instance.showSidebar(options);
        }
    }
}
